<!-- <html>

<head>
	<script type="text/javascript" src="./js/jquery-1.6.1.js"></script>
	<script type="text/javascript">
		function jsonCall(){
			var data = {
				"evernote_user":$('#evernote_user').val(),
				"evernote_pass":$('#evernote_pass').val()
				
			};
				
			
			var url = "evernoteservice/evernotelogin/login";
			$.ajax( { 
                url: url,
                data: data,
                type: "POST",
                //processData: true,
                //contentType: "application/json",
                timeout: 10000,
                dataType: "json",
                success: function(res) {                                    
                    alert('res:'+res);            
                },
                error:  function(xhr) {
                	alert('xhr:'+xhr);
                },
            });   


					
			
		}
	</script>
</head>

<body>
<h2>Hello World!</h2>

<form id="evernote_form" action="evernoteservice/evernotelogin" method="post">
	<input type="text" name="evernote_user" value="user" id="evernote_user"/>
	<input type="text" name="evernote_pass" value="pass" id="evernote_pass"/>
	<input type="button" onclick="javascript:jsonCall();" value="Dale"/>
</form>


</body>




</html-->

<%@ page session="false" %>
<%@ taglib prefix='c' uri='http://java.sun.com/jstl/core' %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>


<%@page import="com.notecalendar.ws.beans.EvernoteLogin"%>
<%@page import="org.springframework.security.core.context.SecurityContextHolder"%><html>



<% request.setAttribute("evernotelogin", new EvernoteLogin()); %>
	<head>
		<title>Create Provider</title>
		<script type="text/javascript" src="<c:url value="/js/jquery-1.6.1.js" /> "></script>
		<script type="text/javascript" src="<c:url value="/js/jquery.json-2.2.min.js" /> "></script>
		<!--script type="text/javascript" src="<c : url value="/js/jquery-1.4.min.js" /> "></script>
		<script type="text/javascript" src="<c : url value="/js/json.min.js" /> "></script-->
		
		<script type="text/javascript">	

	$.fn.serializeObject = function()
	{
	    var o = {};
	    var a = this.serializeArray();
	    $.each(a, function() {
		if (o[this.name] !== undefined) {
		    if (!o[this.name].push) {
			o[this.name] = [o[this.name]];
		    }
		    o[this.name].push(this.value || '');
		} else {
		    o[this.name] = this.value || '';
		}
	    });
	    return o;
	};
	
	
	$(document).ready(function() {
		$("#evernotelogin").submit(function() {
			/*var account = $(this).serializeObject();
			$.postJSON("evernoteservice/evernotelogin/login", account, function(data) {
				alert(data);
				//$("#assignedId").val(data);
				//showPopup();
			});*/
		
			var account = JSON.stringify($(this).serializeObject());
			alert( account );
			$.ajax( { 
                url: "services/evernotelogin/login",
                data: account,
                type: "POST" ,
                //processData: true,
                contentType: "application/json",
                timeout: 10000,
                dataType: "json",
                success: function(res) {                                    
                    alert('res:'+res);    
                    alert( "id:"+res.evernoteloginresponse.evernote_id);        
                },
                error:  function(xhr) {
                	alert('xhr:'+xhr);
                },
            }); 
			return false;				
		});
	});
	
	
	

	function searchNotes(authContext,shardId){
		//var data = "auth:"+authContext;
		/*var content = $("#formGetnotes");
		//alert(content);
		//alert(content.serializeObject());
		var content2 = content.serializeObject();
		/*var n = {
		    authContext: authContext,
		    shardId: shardId
		}
		//var content = new Array("shardId:"+shardId,"authContext:"+authContext);
		alert(n);
		//var content2 = content.serializeObject();
		//var content2 = content.serialize();
		var content2 = n.serializeObject();*/
		/*$.ajax({
			url: "services/ntcs/noteList",
			data:$("#formGetnotes").serialize(),
			type: "POST",
			contentType: "application/html",
			success: function(res){
					alert('res:'+res);
				},
			error: function(xhr){
					alert('xhr:'+xhr);
				},	
			});*/
			
		$.post("services/ntcs/noteList", $("#formGetnotes").serialize(),
		   function(data) {
		     alert("Data Loaded: " + data);
		   });
	}
	
	

	</script>
		
	</head>
	<body>
		AuthContext:<%=SecurityContextHolder.getContext().getAuthentication().getDetails()	%>
		USER:<c:out value="${user}"></c:out><br/>
		USER.ATUH:<c:out value="${user.authToken}"></c:out><br/>
		USER.SHARDId:<c:out value="${user.shardId}"></c:out><br/>
		
		<div class="container">
			
			<div class="span-12 last">	
				<form:form modelAttribute="evernotelogin" action="evernoteservice/evernotelogin/login" method="post">
				  	<fieldset>		
						<legend>Provider Fields</legend>
						<p>
							
							<form:label for="evernote_user" path="evernote_user" cssErrorClass="error">Name</form:label><br/>
							<form:input path="evernote_user" /><form:errors path="evernote_user" />
						</p>
						<p>
							
							<form:label for="evernote_pass" path="evernote_pass" cssErrorClass="error">Pass</form:label><br/>
							<form:input path="evernote_pass" /><form:errors path="evernote_pass" />
						</p>
						<p>	
							<input id="create" type="submit" value="Create" />
						</p>
						
					</fieldset>
				</form:form>
			</div>
			<a href="<c:url value="/j_spring_security_logout"/>">Logout</a>
			
			<p>	
				<input id="notes" type="button" value="GetNotes" onclick="javascript:searchNotes('<c:out value="${user.authToken}"/>','<c:out value="${user.shardId}"/>')" />
			</p>
			<form id="formGetnotes" action="services/ntcs/noteList" method="post">
				<input type="hidden" name="authContext" value="<c:out value="${user.authToken}"/>"/>
				<input type="hidden" name="shardId" value="<c:out value="${user.shardId}"/>"/>
				<input type="submit" value="Dale"/>
			</form>
		</div>
		
	</body>

	
	
</html>

